import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(error => error)
}
const routes = [
  {
    path: '/',
    redirect: '/discover'
  },
  {
    path: '/discover',
    name: 'discover',
    component: () => import('@/views/discover')
  },
  {
    path: '/mv',
    name: 'mv',
    component: () => import('@/views/mv')
  },
  {
    path: '/rank_list',
    name: 'rank_list',
    component: () => import('@/views/rank_list')
  },
  {
    path: '/singer',
    name: 'singer',
    component: () => import('@/views/singer')
  },
  {
    path: '/song_list',
    name: 'song_list',
    component: () => import('@/views/song_list')
  },
  {
    path: '/album',
    name: 'album',
    component: () => import('@/views/album')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search')
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  next()
})
router.afterEach((to, from) => {
  scrollTo(0, 0)
})
export default router
